package com.epidemic.project;

import com.epidemic.common.utils.security.ShiroUtils;
import com.epidemic.framework.web.controller.BaseController;
import com.epidemic.project.system.schedule.domain.SysSchedule;
import com.epidemic.project.system.schedule.service.ISysScheduleService;
import com.epidemic.project.system.tongzhi.domain.SysTongZhi;
import com.epidemic.project.system.tongzhi.service.ISysTongZhiService;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: Epidemic-master
 * @ClassName: PcIndexController
 * @description: pc
 * @author: hanP
 * @create: 2022-12-02 10:36
 **/
@Controller
@RequestMapping("/pc/")
public class PcIndexController extends BaseController {

    @Autowired
    private ISysTongZhiService sysTongZhiService;
    @Autowired
    private ISysScheduleService sysScheduleService;

    private Integer pcPageSize = 12;

    private String prefix = "pc/view";

    // 系统首页
    @GetMapping("/index")
    public String index(ModelMap mmap) {
        pcStartPage(8);
        SysTongZhi sysTongZhi = new SysTongZhi();
        List<SysTongZhi> sysTongZhis = sysTongZhiService.selectSysTongZhiList(sysTongZhi);
        if (sysTongZhis != null && sysTongZhis.size() > 0) {
            SysTongZhi sysTongZhi1 = sysTongZhis.get(0);
            mmap.put("gongGaosF", sysTongZhi1.getImg());
        } else {
            mmap.put("gongGaosF", "");
        }
        mmap.put("gongGaos", sysTongZhis);
        return prefix + "/index";
    }

    // 系统首页
    @GetMapping("/center")
    public String kcb(ModelMap mmap,
                      @RequestParam(value = "typeId", defaultValue = "4") String typeId,
                      @RequestParam(value = "pageNum", defaultValue = "1") int pageNum) {

        Long userId = null;
        try {
            userId = ShiroUtils.getUserId();
        } catch (Exception e) {
            return "redirect:/login";
        }

        if (ShiroUtils.getSysUser().isAdmin()) {
            return "redirect:/index";
        }
        switch (typeId) {
            case "1":
                mmap.put("pageInfo", "/system/sysInOut");
                break;
            case "2":
                mmap.put("pageInfo", "/system/leave");
                break;
            case "3":
                mmap.put("pageInfo", "/system/wuzi");
                break;
            case "4":
                mmap.put("pageInfo", "/system/user/profile");
                break;
            case "5":
                mmap.put("pageInfo", "/system/temperature");
                break;
            case "6":
                break;
            case "7":
                mmap.put("pageInfo", "/system/schedule");
                break;
            case "8":
                mmap.put("pageInfo", "/system/jiaoliu");
                break;
            case "9":
                mmap.put("pageInfo", "/system/kuang");
                break;
            default:
        }
        mmap.put("typeId", StringUtils.isBlank(typeId) ? "" : typeId);

        return prefix + "/center";
    }


}
